package com.suray.attendance.common.utils;

public class StringUtils {

    /**
    * @Description: 小写驼峰规则
    * @Param: [underscoreCase]
    * @return: java.lang.String
    * @Author: jly
    * @Date: 2023/12/2
    */
    public static String toCamelCase(String underscoreCase) {
        StringBuilder camelCase = new StringBuilder();
        boolean nextUpperCase = false;

        for (int i = 0; i < underscoreCase.length(); i++) {
            char c = underscoreCase.charAt(i);

            if (c == '_') {
                nextUpperCase = true;
            } else {
                if (nextUpperCase) {
                    camelCase.append(Character.toUpperCase(c));
                    nextUpperCase = false;
                } else {
                    camelCase.append(Character.toLowerCase(c));
                }
            }
        }

        return camelCase.toString();
    }

    /**\
     * 小写字母中划线隔开
     * @param camelCase
     * @return
     */
    public static String toUnderscoreCase(String camelCase) {
        StringBuilder underscoreCase = new StringBuilder();

        for (int i = 0; i < camelCase.length(); i++) {
            char c = camelCase.charAt(i);

            if (Character.isUpperCase(c)) {
                underscoreCase.append('_');
                underscoreCase.append(Character.toLowerCase(c));
            } else {
                underscoreCase.append(c);
            }
        }

        return underscoreCase.toString();
    }

}